﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cosmetic.Logic;

namespace WebApp.Space.AccountInfo
{
    public partial class MyFavorite : PageBase
    {
        ProductManager m_ProductManager = new ProductManager();
        UserManager m_UserManager = new UserManager();
        Cosmetic.DataEntity.Product m_Product;
        Cosmetic.DataEntity.ProductInfo m_ProductInfo;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.SignInUser == null)
            {
                Page.RegisterClientScriptBlock("key", "<script>window.top.location = '/Login.aspx';</script>");
                return;
            }
            if (!IsPostBack)
            {
                this.Bind();
            }
        }

        private void Bind()
        {
            this.lvProduct.DataSource = m_ProductManager.GetFavoriteProductInfo(this.SignInUser.UserId);
            this.lvProduct.DataBind();
        }

        protected void lvProduct_PagePropertiesChanged(object sender, EventArgs e)
        {
            Bind();
        }

        protected void lvProduct_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                if (e.CommandName.Equals("OnDelete"))
                {
                    m_UserManager.DeleteFavorite(SignInUser.UserId, new Guid(e.CommandArgument.ToString()));
                }
            }
            this.Bind();
        }
    }
}